//
//  roman_digital.hpp
//  algrithem_practice
//
//  Created by huge on 2022/3/31.
//  Copyright © 2022 huge. All rights reserved.
//

#ifndef roman_digital_hpp
#define roman_digital_hpp

#include <stdio.h>

#include <unordered_map>
#include <string>
class roman_digital{
public:
    roman_digital(){};
private:
    std::unordered_map<char, int>symbolValues = {
        {'I',1},
        {'V', 5},
        {'X', 10},
        {'L', 50},
        {'C', 100},
        {'D', 500},
        {'M', 1000},
    };
    
public:
    
    int roman_to_int(std::string s){
        int sum = 0;
        int n = static_cast<int>(s.length());
        for (int i = 0; i < n; i++) {
            int value = symbolValues[s[i]];
            if (i < n-1 && value < symbolValues[s[i+1]]) {
                sum -= value;
            }else{
                sum += value;
            }
        }
        return sum;
    }
};

#endif /* roman_digital_hpp */
